<!--
 * @Description: 
 * @Author: charles
 * @Date: 2021-10-21 15:32:05
 * @LastEditors: charles
 * @LastEditTime: 2021-10-21 15:44:55
-->
<template>
  <div class="login">
    <h3 style="text-align:center">登录</h3>
    <van-form @submit="loginHandler">
      <van-cell-group inset>
        <van-field
          v-model="form.username"
          name="用户名"
          label="用户名"
          placeholder="用户名"
          :rules="[{ required: true, message: '请填写用户名' }]"
        />
        <van-field
          v-model="form.password"
          type="password"
          name="密码"
          label="密码"
          placeholder="密码"
          :rules="[{ required: true, message: '请填写密码' }]"
        />
      </van-cell-group>
      <div style="margin: 16px;">
        <van-button round block type="primary" native-type="submit">
          提交
        </van-button>
      </div>
    </van-form>
  </div>
</template>
<script>
import {postJSON} from '../utils/request'
export default {
  setup() {
    
  },
  data(){
    return {
      form:{}
    }
  },
  methods:{
    loginHandler(){
      let url = "/user/login"
      postJSON(url,this.form).then(resp=>{
        let token = resp.data.token;
        localStorage.setItem('token',token);
        this.$router.push("/home")
      })
    }
  }
}
</script>
<style scoped>

</style>

